package UDP;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package UDP
 * @date 2024/4/17 上午11:10
 */
public class Day11_server {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(8888);
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
        socket.receive(packet);
        buffer = packet.getData();
        String ss = new String(buffer, 0, packet.getLength());
        System.out.println(ss);
        /////////////////////////////////////////////////////////
        String cc = ss.toUpperCase();
        byte[] arr = cc.getBytes();
        InetAddress addr = InetAddress.getLocalHost();
        DatagramPacket packet1 = new DatagramPacket(arr, arr.length, addr, 8888);
        socket.send(packet1);

    }
}
